# -*- coding: utf-8 -*-

import os,subprocess

SOURCE_PATH = u'./'
TARGET_PATH = '../../poker_client/Assets/Script/Proto'
CMD_GEN = r'./ProtoGen.exe'

def doConvertFile(path):
	print(path)
	dirname = os.path.dirname(path)
	filename = os.path.basename(path);
	csname = os.path.abspath(os.path.join(TARGET_PATH, filename.replace('.proto', '.cs')));
	ns = 'message' # proto文件中有package了，则此处的默认命名空间无效

	cmd = '"{0}" -i:{1} -o:{2} -ns:{3}'.format(CMD_GEN, os.path.abspath(path), csname, ns);
	#print(cmd)
	subprocess.call(cmd);


def doConvert(path):
	if not os.path.exists(TARGET_PATH):
		os.makedirs(TARGET_PATH)

	for root, dirs, files in os.walk(path):
		for file in files:
			if file.endswith('.proto'):
				doConvertFile(os.path.join(root, file))


doConvert(SOURCE_PATH)
os.system('PAUSE')
